﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using Javavaj.iHunter;
using Javavaj.iHunter.Database;


namespace Javavaj.iHunter.Core
{
    public partial class GlobalSettings 
    {
        public GlobalSettings(UserDbDataSet dataSet)
        {
            this.dataSet = dataSet;
        }
        UserDbDataSet dataSet;

        private UserDbDataSet.GlobalSettingsRow GetTableRow()
        {
            UserDbDataSet.GlobalSettingsRow row = null;
            if (dataSet.GlobalSettings.Count == 0)
            {
                row = dataSet.GlobalSettings.NewGlobalSettingsRow();
                row.AutoUpdate = true;
                row.AutoUpdateInterval = TimeSpan.FromMinutes(30);
                row.AutoDownloadFile = true;
                row.AutoDownloadSizeLimit = -1;
                row.Rank = 50;
                row.Language = string.Empty;
                dataSet.GlobalSettings.AddGlobalSettingsRow(row);
                dataSet.GlobalSettings.AcceptChanges();
            }
            else
            {
                row = dataSet.GlobalSettings[0];
            }
            return row;
        }

        public bool AutoUpdate
        {
            get
            {
                return GetTableRow().AutoUpdate;
            }
            set
            {
                GetTableRow().AutoUpdate = value;
                dataSet.GlobalSettings.AcceptChanges();
            }
        }
        public TimeSpan AutoUpdateInterval
        {
            get
            {
                return GetTableRow().AutoUpdateInterval;
            }
            set
            {
                GetTableRow().AutoUpdateInterval = value;
                dataSet.GlobalSettings.AcceptChanges();
            }
        }
        public bool AutoDownloadFile
        {
            get
            {
                return GetTableRow().AutoDownloadFile;
            }
            set
            {
                GetTableRow().AutoDownloadFile = value;
                dataSet.GlobalSettings.AcceptChanges();
            }
        }
        public Int64 AutoDownloadSizeLimit
        {
            get
            {
                return GetTableRow().AutoDownloadSizeLimit;
            }
            set
            {
                GetTableRow().AutoDownloadSizeLimit = value;
                dataSet.GlobalSettings.AcceptChanges();
            }
        }
        public string Language
        {
            get
            {
                return GetTableRow().Language;
            }
            set
            {
                GetTableRow().Language = value;
                dataSet.GlobalSettings.AcceptChanges();
            }
        }
        public int Rank
        {
            get
            {
                return GetTableRow().Rank;
            }
            set
            {
                GetTableRow().Rank = value;
                dataSet.GlobalSettings.AcceptChanges();
            }
        }
    }
}
